var oss = require('ali-oss')

var ossMap = {}

function getOssInfo(config, bucket) {
  return getByBucket(config, bucket)
}

function getByBucket(config, bucket){
  if(!ossMap[bucket]){
    var ossConfig = config.oss[bucket]
    var ossClient = oss({
      accessKeyId: ossConfig.accessKeyId,
      accessKeySecret: ossConfig.accessKeySecret,
      bucket: ossConfig.bucket,
      endpoint: ossConfig.endpoint,
      timeout: "180s"
    })
    ossMap[bucket] = {ossClient, ossConfig}
  }
  return ossMap[bucket]
}



module.exports = {
  getOssInfo
}